# -*- coding: utf-8 -*-
from django.db import models
from decimal import *

# Create your models here.
class Company(models.Model):
    stock_code = models.CharField(max_length = 10)
    name = models.CharField(max_length = 128)
    description = models.TextField()
    address = models.CharField(max_length = 256, blank = True)
    tel = models.CharField(max_length = 32, blank = True)
    fax = models.CharField(max_length = 32, blank = True)
    employees = models.CharField(max_length = 32, blank = True)
    employees_number = models.IntegerField(blank = True, null = True)
    update_at = models.CharField(max_length = 32, blank = True)
    homepage = models.CharField(max_length = 512, blank = True)
    news_link = models.CharField(max_length = 512, blank = True)
    investor_relations_link = models.CharField(max_length = 512, blank = True)
    financial_info_link = models.CharField(max_length = 512, blank = True)
    history_link = models.CharField(max_length = 512, blank = True)
    executives_link = models.CharField(max_length = 512, blank = True)
    products_link = models.CharField(max_length = 512, blank = True)
    employment_link = models.CharField(max_length = 512, blank = True)
    mkt_cap_decimal = models.DecimalField(max_digits = 24, decimal_places=0, blank = True, null = True)
    mkt_cap = models.CharField(max_length = 32, blank = True)

    def __unicode__(self):
        return '%s (%s)' % (self.name, self.stock_code)

    class Meta:
        ordering = ['stock_code']

class Officer(models.Model):
    company = models.ForeignKey(Company)
    first_name = models.CharField(max_length = 32, blank = True)
    last_name = models.CharField(max_length = 32, blank = True)
    qualification = models.CharField(max_length = 32, blank = True)
    title = models.CharField(max_length = 128, blank = True)
    OFFICER_LEVEL = (
            ('1', 'CEO/P'),
            ('2', 'VP/ED'),
            ('3', 'D')
    )
    level = models.CharField(max_length = 1, choices = OFFICER_LEVEL)
    common_name = models.CharField(max_length = 128, blank = True)
    work_tel = models.CharField(max_length = 32, blank = True)
    fax = models.CharField(max_length = 32, blank = True)
    mobile = models.CharField(max_length = 32, blank = True)
    email1 = models.EmailField(blank = True)
    email2 = models.EmailField(blank = True)

    def __unicode__(self):
        return '%s %s' % (self.first_name, self.last_name)


class HKSFCCompany(models.Model):
    name = models.CharField(max_length = 128)
    name_ch = models.CharField(max_length = 128)
    #address = models.CharField(max_length = 1500, blank = True)
    tel = models.CharField(max_length = 32, blank = True)
    fax = models.CharField(max_length = 32, blank = True)
    homepage = models.CharField(max_length = 512, blank = True)
    email_suffix = models.CharField(max_length = 128, blank = True)
    
    def address(self):
        list=''
        for item in self.hksfccompanyaddress_set.order_by('orderby'):
            list = list + '<li style="color:%s">%s</li>' % (item.isPostAddr and "green" or "black", item.address)
        return "<ul>"+list+"</ul>"
    address.allow_tags = True
        
    def __unicode__(self):
        return '%s' % (self.name)

class HKSFCCompanyAddress(models.Model):
    company = models.ForeignKey(HKSFCCompany)
    orderby = models.IntegerField()
    address = models.CharField(max_length = 1500, blank = True)
    isPostAddr = models.BooleanField(default = False)
    
    def __unicode__(self):
        return '%s' % (self.address)
    
class HKSFCOfficer(models.Model):
    company = models.ForeignKey(HKSFCCompany)
    name_en = models.CharField(max_length = 128, blank = True)
    name_ch = models.CharField(max_length = 32, blank = True)
    reg_no = models.CharField(max_length = 32, blank = True)
    OFFICER_CLASSIFYING = (
            ('1', 'Responsible Officers'),
            ('2', 'Representatives')
    )
    classifying = models.CharField(max_length = 1, choices = OFFICER_CLASSIFYING)

    def __unicode__(self):
        return '%s' % (self.name_en)

class HKSFC_SPO_RO(models.Model):
    company = models.ForeignKey(HKSFCCompany)
    name_en = models.CharField(max_length = 128, blank = True)
    name_ch = models.CharField(max_length = 32, blank = True)
    reg_no = models.CharField(max_length = 32, blank = True)
    
    def __unicode__(self):
        return '%s' % (self.name_en)
    
class HKSFC_SPO_RR(models.Model):
    company = models.ForeignKey(HKSFCCompany)
    name_en = models.CharField(max_length = 128, blank = True)
    name_ch = models.CharField(max_length = 32, blank = True)
    reg_no = models.CharField(max_length = 32, blank = True)
    
    def __unicode__(self):
        return '%s' % (self.name_en)
    
class Foreign_Cos_in_China(models.Model):
    company_code = models.CharField(max_length = 128,verbose_name="企业代码")
    company_name = models.CharField(max_length = 256,verbose_name="企业名称")
    address = models.CharField(max_length = 256,verbose_name="通信地址")
    china_investor1 =  models.CharField(max_length = 256,verbose_name="中方投资企业名称(一)")
    china_investor2 =  models.CharField(max_length = 256,verbose_name="中方投资企业名称(二)")
    china_investor3 =  models.CharField(max_length = 256,verbose_name="中方投资企业名称(三)")
    foreign_investor1 =  models.CharField(max_length = 256,verbose_name="外方投资企业名称(一)")
    foreign_investor2 =  models.CharField(max_length = 256,verbose_name="外方投资企业名称(二)")
    foreign_investor3 =  models.CharField(max_length = 256,verbose_name="外方投资企业名称(三)")
    COUN_CODE =  models.CharField(max_length = 50)
    COUN1_NAME = models.CharField(max_length = 256,verbose_name="国别(一)")
    COUN1 =  models.CharField(max_length = 50)
    COUN2_NAME = models.CharField(max_length = 256,verbose_name="国别(二)")
    COUN2 =  models.CharField(max_length = 50)
    COUN3_NAME = models.CharField(max_length = 256,verbose_name="国别(三)")
    business_range = models.CharField(max_length = 2000,verbose_name="经营范围")
    TRAD_CODE = models.CharField(max_length = 10)
    business_name = models.CharField(max_length = 200,verbose_name="行业名称")
    INVW_CODE = models.CharField(max_length = 20)
    enterprise_type = models.CharField(max_length = 100,verbose_name="企业类型")
    employees = models.FloatField(verbose_name="在职人员")
    foreign_employees = models.FloatField(verbose_name="外籍人员")
    chairman = models.CharField(max_length = 128,verbose_name="董事长")
    president = models.CharField(max_length = 128,verbose_name="总经理")
    mail_code = models.CharField(max_length = 128,verbose_name="邮政编码")
    phone = models.CharField(max_length = 128,verbose_name="电话")
    fax = models.CharField(max_length = 128,verbose_name="传真")
    start_date = models.DateField(verbose_name="投产日期")
    operating_limit = models.IntegerField(verbose_name="经营年限")
    production_status = models.CharField(max_length = 10,verbose_name="投产情况")
    investment = models.FloatField(verbose_name="投资总额（万美元）")
    revenue = models.FloatField(verbose_name="销售营业收入（万美元）")
    CTCODE = models.CharField(max_length = 20)
    
class China_High_School(models.Model):
    logic_id = models.CharField(max_length = 128,verbose_name="id")
    school_code = models.CharField(max_length = 256,verbose_name="学校代码")
    school_name = models.CharField(max_length = 256,verbose_name="学校名称")
    properties_code =  models.CharField(max_length = 256,verbose_name="属性代码")
    mail_code =  models.CharField(max_length = 20,verbose_name="邮政编码")
    address =  models.CharField(max_length = 256,verbose_name="学校地址")
    phone =  models.CharField(max_length = 50,verbose_name="联系电话")
    principal =  models.CharField(max_length = 50,verbose_name="学校校长")
    junior_high_school_students =  models.IntegerField(verbose_name="初中在校生")
    high_school_students =  models.IntegerField(verbose_name="高中在校生")
    
    
    
    
    
    
